﻿using MediatR;
using SlaughterItem.Common.Domains.Detection;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.COA
{
    public class ShowCOADataHandler : IRequestHandler<ShowCOADataCommand, Result>
    {
        public ShowCOADataHandler(IBaseRepository<COAData> cOADataRepository)
        {
            COADataRepository = cOADataRepository;
        }

        public IBaseRepository<COAData> COADataRepository { get; set; }
        public async Task<Result> Handle(ShowCOADataCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCode.Search};
            var list = COADataRepository.GetAll().Where(x=>x.ISDeleteCOA==false).ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
